package com.manage.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manage.modules.domain.TBaseRepairPhoto;
import com.manage.modules.mapper.TBaseRepairPhotoMapper;
import com.manage.modules.service.ITBaseRepairPhotoService;
import com.manage.modules.utils.UploadUtil;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * 维修信息现场照片Service业务层处理
 *
 * @author wx
 * @date 2021-09-10
 */
@Service
public class TBaseRepairPhotoServiceImpl extends ServiceImpl<TBaseRepairPhotoMapper, TBaseRepairPhoto> implements ITBaseRepairPhotoService {
    @Override
    public List<TBaseRepairPhoto> findByRepairId(Long repairId) {
        if (repairId == null) {
            return null;
        }
        LambdaQueryWrapper<TBaseRepairPhoto> lqw = Wrappers.lambdaQuery();
        lqw.eq(true, TBaseRepairPhoto::getRepairId, repairId);
        return list(lqw);
    }

    @Override
    public void deleteByRepairIds(Collection<Long> ids) {
        // 不存在或为空直接返回
        if (ids == null || ids.size() == 0) {
            return;
        }
        LambdaQueryWrapper<TBaseRepairPhoto> lqw = Wrappers.lambdaQuery();
        lqw.in(true, TBaseRepairPhoto::getRepairId, ids);
        List<TBaseRepairPhoto> list = list(lqw);
        delete(list);
    }

    @Override
    public void delete(List<TBaseRepairPhoto> deletePhotoList ) {
        if (deletePhotoList != null && deletePhotoList.size() > 0) {
            for (TBaseRepairPhoto repairPhoto : deletePhotoList) {
                // 删除照片
                UploadUtil.delete(repairPhoto.getLocal());
                // 删除对象
                boolean b = removeById(repairPhoto.getRepairPhotoId());
                System.out.println("删除成功:" + b);
            }
        }

    }
}
